<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-20 21:41:37
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-11-07 22:37:15
 * @Descripttion: 订单
 */

namespace app\api\controller\user\v1_0\driver;


use think\Db;
class Order extends \app\api\controller\user\v1_0\Common
{
    protected $noNeedRight = ['test'];
    /**
     * @Author: 哲学家乔布斯 <wuyangii@qq.com>
     * @brief: 
     * @return 
     * @Descripttion: 确认订单
     */    
    public function confirm(){
        $id = request()->param('id');
        $order = (new \app\common\model\UserOrders())->where([
            'id' => $id
        ])->find();
        // if($order['driver_state'] == 2){
        //     return self::errorResult("该笔订单已经处理完成！！！");
        // }
        Db::startTrans();
        try{
            $message = "订单创建失败,请重试";
            $process = true;

            $row = (new \app\common\model\UserOrders())->where(['id' => $id])->update([
                'state' => 3,
                'driver_state' => 2,
                'bus_state' => 1,
            ]);
            if(!$row){
                $message = "修改订单状态失败,请重试";
                $process = false;
            }
          
           
           
            if ($process !== false) {
                Db::commit(); // 提交事务
            } else {
                Db::rollback(); // 回滚事务
            }
         } catch (\Exception $e) {
            $process = false;
            $message = $e->getMessage();
            Db::rollback(); // 回滚事务
        }
        if ($process !== false) {
            return self::successResult("成功");
        } else {
            return self::errorResult($message);
        }

    }

    
    

}
